//
//  JKRRecommendUserTableViewCell.m
//  百思不得姐
//
//  Created by Lucky on 16/3/1.
//  Copyright © 2016年 Lucky. All rights reserved.
//

#import "JKRRecommendUserTableViewCell.h"

@interface JKRRecommendUserTableViewCell ()

@property (nonatomic, strong) UIImageView *iconView;

@property (nonatomic, strong) UILabel *nameLabel;

@property (nonatomic, strong) UILabel *fansLabel;

@property (nonatomic, strong) UIButton *attentionButton;

@property (nonatomic, strong) UIView *bottomLine;

@end

@implementation JKRRecommendUserTableViewCell

+ (CGFloat)heightWithModel:(JKRRecommentUser *)model
{
    JKRRecommendUserTableViewCell *cell = [[JKRRecommendUserTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
    cell.model = model;
    
    [cell layoutIfNeeded];
    
    CGRect frame = cell.iconView.frame;
    
    return frame.origin.y + frame.size.height + 21;
}

- (void)setModel:(JKRRecommentUser *)model
{
    _model = model;
    self.nameLabel.text = model.screen_name;
    self.fansLabel.text = [NSString stringWithFormat:@"%zd人关注", model.fans_count];
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.header] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"]];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.iconView];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.fansLabel];
        [self.contentView addSubview:self.attentionButton];
        [self.contentView addSubview:self.bottomLine];
        
        [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(20);
            make.leading.equalTo(self.contentView).offset(10);
            make.width.equalTo(@50);
            make.height.equalTo(@50);
        }];
        
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.iconView.mas_top);
            make.leading.equalTo(self.iconView.mas_trailing).offset(10);
            make.trailing.equalTo(self.contentView);
        }];
        
        [self.fansLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.iconView.mas_bottom);
            make.leading.equalTo(self.iconView.mas_trailing).offset(10);
            make.trailing.equalTo(self.contentView);
        }];
        
        [self.attentionButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@32);
            make.width.equalTo(@50);
            make.height.equalTo(@25);
            make.trailing.equalTo(self.contentView).offset(-10);
        }];
        
        [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.iconView.mas_bottom).offset(20);
            make.leading.equalTo(self.contentView);
            make.trailing.equalTo(self.contentView);
            make.height.mas_equalTo(@0.5);
        }];
    }
    return self;
}

- (UIImageView *)iconView
{
    if (!_iconView) {
        _iconView = [[UIImageView alloc] init];
    }
    return _iconView;
}

 - (UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
    }
    return _nameLabel;
}

- (UILabel *)fansLabel
{
    if (!_fansLabel) {
        _fansLabel = [[UILabel alloc] init];
    }
    return _fansLabel;
}

- (UIButton *)attentionButton
{
    if (!_attentionButton) {
        _attentionButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_attentionButton setBackgroundImage:[UIImage imageNamed:@"FollowBtnBg"] forState:UIControlStateNormal];
        [_attentionButton setBackgroundImage:[UIImage imageNamed:@"FollowBtnClickBg"] forState:UIControlStateHighlighted];
        [_attentionButton setTitle:@"+关注" forState:UIControlStateNormal];
        [_attentionButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [_attentionButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted];
    }
    return _attentionButton;
}

- (UIView *)bottomLine
{
    if (!_bottomLine) {
        _bottomLine = [[UIView alloc] init];
        _bottomLine.backgroundColor = [UIColor lightGrayColor];
    }
    return _bottomLine;
}

@end
